package com.zmn.oms.dubbo.impl.zmn.normal.order;

import org.apache.dubbo.config.annotation.Service;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.oms.dubbo.dto.zmn.order.OrderChangeRecordDRO;
import com.zmn.oms.dubbo.interfaces.zmn.normal.order.OrderChangeRecordRemoteService;
import com.zmn.oms.dubbo.utils.DubboConsts;
import com.zmn.oms.model.entity.changerecord.OrderChangeRecord;
import com.zmn.oms.services.interfaces.changerecord.OrderChangeRecordService;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.Objects;
import java.util.Optional;

/**
 * 订单修改记录远程服务
 *
 * @author hankangshuai
 * @since 2019/12/4
 **/
@Service(loadbalance = "roundrobin", timeout = 20000, version = DubboConsts.INTERFACE_VERSION, validation = "true")
public class OrderChangeRecordRemoteServiceImpl implements OrderChangeRecordRemoteService {
    @Resource
    private OrderChangeRecordService orderChangeRecordService;

    /**
     * 根据订单ID查询
     *
     * @param orderId 订单ID
     */
    @Override
    public ResponseDTO<OrderChangeRecordDRO> getByOrderId(@NotNull Long orderId) {
        OrderChangeRecord changeRecordByOrderId = orderChangeRecordService.getChangeRecordByOrderId(orderId);
        OrderChangeRecordDRO changeRecordDro = Optional.ofNullable(changeRecordByOrderId).map(orderChangeRecord -> {
            OrderChangeRecordDRO orderChangeRecordDro = new OrderChangeRecordDRO();
            orderChangeRecordDro.setOrderId(orderChangeRecord.getOrderId());
            orderChangeRecordDro.setFirstDutyTime(orderChangeRecord.getFirstDutyTime());
            orderChangeRecordDro.setFirstDutyOptId(orderChangeRecord.getFirstDutyOptId());
            orderChangeRecordDro.setFirstDutyOptName(orderChangeRecord.getFirstDutyOptName());
            orderChangeRecordDro.setFirstDutyOptType(orderChangeRecord.getFirstDutyOptType());
            orderChangeRecordDro.setFirstDutyOptTime(orderChangeRecord.getFirstDutyOptTime());
            orderChangeRecordDro.setFirstVisitScanTime(orderChangeRecord.getFirstVisitScanTime());
            orderChangeRecordDro.setFirstMasterImageTime(orderChangeRecord.getFirstMasterImageTime());
            orderChangeRecordDro.setLastVisitScanTime(orderChangeRecord.getLastVisitScanTime());
            orderChangeRecordDro.setLastMasterImageTime(orderChangeRecord.getLastMasterImageTime());
            orderChangeRecordDro.setLastDutyTime(orderChangeRecord.getLastDutyTime());
            orderChangeRecordDro.setLastDutyOptId(orderChangeRecord.getLastDutyOptId());
            orderChangeRecordDro.setLastDutyOptName(orderChangeRecord.getLastDutyOptName());
            orderChangeRecordDro.setLastDutyOptType(orderChangeRecord.getLastDutyOptType());
            orderChangeRecordDro.setLastDutyOptTime(orderChangeRecord.getLastDutyOptTime());
            orderChangeRecordDro.setDutyTimeModifyCount(orderChangeRecord.getDutyTimeModifyCount());
            orderChangeRecordDro.setFirstDistributeTime(orderChangeRecord.getFirstDistributeTime());
            orderChangeRecordDro.setFirstDistributeOptId(orderChangeRecord.getFirstDistributeOptId());
            orderChangeRecordDro.setFirstDistributeOptName(orderChangeRecord.getFirstDistributeOptName());
            orderChangeRecordDro.setFirstDistributeOptType(orderChangeRecord.getFirstDistributeOptType());
            orderChangeRecordDro.setFirstDistributeOptTime(orderChangeRecord.getFirstDistributeOptTime());
            orderChangeRecordDro.setFirstDistributeType(orderChangeRecord.getFirstDistributeType());
            orderChangeRecordDro.setLastDistributeTime(orderChangeRecord.getLastDistributeTime());
            orderChangeRecordDro.setLastDistributeOptId(orderChangeRecord.getLastDistributeOptId());
            orderChangeRecordDro.setLastDistributeOptName(orderChangeRecord.getLastDistributeOptName());
            orderChangeRecordDro.setLastDistributeOptType(orderChangeRecord.getLastDistributeOptType());
            orderChangeRecordDro.setLastDistributeOptTime(orderChangeRecord.getLastDistributeOptTime());
            orderChangeRecordDro.setLastDistributeType(orderChangeRecord.getLastDistributeType());
            orderChangeRecordDro.setDistributeCount(orderChangeRecord.getDistributeCount());
            return orderChangeRecordDro;
        }).orElse(null);
        return ResponseDTO.success(changeRecordDro);
    }
}
